<template>
	<view class="invite">
		<view class="nav">
			<uni-nav-bar backgroundColor="transparent" left-icon="left" color="#FFF" @clickLeft="goback"></uni-nav-bar>
		</view>
		
		<view class="share_people flex_r_between" v-if="!Array.isArray(info.parent_info)">
			<view class="left">推广人：</view>
			<view class="right flex">
				<image :src="info.parent_info && info.parent_info.avatar" mode="aspectFill"></image>
				<text class="hidden">{{info.parent_info && info.parent_info.nickname}}</text>
			</view>
		</view>
		
		<view class="input flex_r_between" v-else>
			<input type="text" placeholder="请输入邀请码" placeholder-class="input_place" v-model="sn" />
			<view class="btn" @click="sendCode">绑定</view>
		</view>
		
		
		
		
		
		<view class="card flex_c">
			<view class="title flex_c"> <text>我的专属邀请码</text> </view>
			<view class="code flex">
				<view class="item flex_c" v-for="(item,index) in info.sn" :key="index">
					<text>{{item}}</text>
					<i></i>
				</view>
			</view>
			<view class="btn" @click="onCopy(info.sn)">一键复制</view>
			<view class="people">已邀请：{{info.share_num || 0}}人</view>
			<view class="line"></view>
			<view class="btn_share" @click="share">一键邀请</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				sn:'',
				
				info:{},
			}
		},
		methods: {
			goback(){ uni.navigateBack() },
			sendCode(){
				this.request.httpTokenRequest({
					url: "user/savePid",
					method: "get"
				}, {
					sn:this.sn
				}).then(data => {
					if (data.code == 0) {
						this.getInfo()
						this.$util.msg(data.msg)
					}else {
						this.$util.msg(data.msg)
					}
				}, error => {})
			},
			onCopy(e){
				uni.setClipboardData({
					data:e,
					success:res=> {
						this.$util.msg('已复制到剪切板')
					}
				})
			},
			getInfo(){
				this.request.httpTokenRequest({
					url: "user/info",
					method: "get"
				}, {
					sn:this.sn
				}).then(res => {
					if (res.code == 0) {
						this.info = res.data
					}else {
						this.$util.msg(res.msg)
					}
				}, error => {})
			},
			share(){
				this.request.httpTokenRequest({
					url: "index/getShareConfig",
					method: "get"
				}, {
					type:1
				}).then(data => {
					if (data.code == 0) {
						uni.share({
							provider: "weixin",
							scene: "WXSceneSession",
							type: 0,
							href: data.data.path + '?pid=' + this.info.user_id, // 跳转链接
							title: data.data.title, // 分享标题
							summary: data.data.content,
							imageUrl: data.data.image,
							success: function (res) {
								// console.log("success:" + JSON.stringify(res));
							},
							fail: function (err) {
								console.log("fail:" + JSON.stringify(err));
							}
						});
					}else {
						this.$util.msg(data.msg)
					}
				}, error => {})
			}
		},
		onLoad() {
			this.getInfo()
		}
	}
</script>

<style lang="less" scoped>
	.nav {
		position: fixed;
		top: 0;
		left: 0;
		padding-top: var(--status-bar-height);
	}
	.invite {
		background: url('https://qiniu-cdn.maeiyun.com/imgs/mine/invite_2_bg.png') 0 0 no-repeat;
		background-size: 100%;
		min-height: 100vh;
		padding: 700rpx 22rpx 10rpx;
		box-sizing: border-box;
		background-color: #FAD2A3;
	}
	
	.share_people {
		height: 93rpx;
		background: rgba(255,255,255,0.3);
		border-radius: 47rpx;
		border: 1rpx solid #FFFFFF;
		padding: 0 38rpx;
		.left {
			font-size: 26rpx;
			color: #B40400;
			line-height: 37rpx;
		}
		.right {
			align-items: center;
			image {
				width: 60rpx;
				height: 60rpx;
				border-radius: 50%;
			}
			text {
				font-size: 30rpx;
				color: #000000;
				line-height: 48rpx;
				margin-left: 10rpx;
				max-width: 300rpx;
			}
		}
	}
	
	.input {
		height: 93rpx;
		background: rgba(255,255,255,0.3);
		border-radius: 47rpx;
		border: 1rpx solid #FFFFFF;
		padding: 0 16rpx;
		input {
			font-size: 30rpx;
			color: #333;
			line-height: 42rpx;
			flex: 1;
			margin-left: 20rpx;
		}
		.input_place {
			color: rgba(180,4,0,0.5);
		}
		.btn {
			width: 170rpx;
			height: 68rpx;
			background: #FD0F1F;
			border-radius: 34rpx;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 68rpx;
			text-align: center;
		}
	}

	.card {
		background: rgba(255,255,255,0.3);
		border-radius: 20rpx;
		border: 1rpx solid #FFFFFF;
		margin-top: 26rpx;
		padding: 65rpx 0 40rpx;
		.title {
			width: 298rpx;
			height: 37rpx;
			background: #FFFFFF;
			border-radius: 47rpx;
			text {
				font-weight: 600;
				font-size: 30rpx;
				color: #B40400;
				margin-top: -10rpx;
			}
		}
		.code {
			margin: 30rpx 0;
			.item {
				margin: 0 10rpx;
				text {
					font-weight: 600;
					font-size: 80rpx;
					color: #B40400;
					line-height: 112rpx;
				}
				i {
					width: 50rpx;
					height: 1rpx;
					border: 2rpx solid #B40400;
				}
			}
		}
		.btn {
			width: 298rpx;
			height: 69rpx;
			background: #FD0F1F;
			border-radius: 47rpx;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 69rpx;
			text-align: center;
		}
		.people {
			font-size: 26rpx;
			color: #000000;
			line-height: 37rpx;
			margin: 21rpx 0 27rpx;
		}
		.line {
			width: 635rpx;
			border-bottom: 1rpx dashed rgba(85,85,85,0.42);
			margin-bottom: 100rpx;
		}
		.btn_share {
			width: 298rpx;
			height: 70rpx;
			background: #FFFFFF;
			border-radius: 49rpx;
			font-size: 32rpx;
			color: #2C2C2C;
			line-height: 70rpx;
			text-align: center;
		}
	}


</style>
